package com.qwt.part_time_api.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.qwt.part_time_api.error.BusinessException;
import com.qwt.part_time_api.service.TaskService;
import com.qwt.part_time_api.vo.Result;
import com.qwt.part_time_api.vo.SuggestionVo;
import com.qwt.part_time_api.vo.TaskDetailVo;
import com.qwt.part_time_api.vo.TaskListVo;
import com.qwt.part_time_api.vo.params.PageParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 君子慎独
 * @create 2021/12/24 0024 13:09
 */
@RestController
@RequestMapping("/task")
@Api(tags = {"任务列表"})
public class TaskController {

    @Autowired
    private TaskService taskService;

    /**
     * 首页任务列表
     *
     * @param params 页数，每页的条数
     * @return 返回拥有《置顶》这一个关键
     */

    @PostMapping("/taskList")
    @ApiOperation(value = "首页-任务列表", notes = "首页列表展示")
    @ApiOperationSupport(author = "Tzeao",
            includeParameters = {"params.page",
                    "params.pageSize",
                    "params.region",
                    "params.order"})
    @ApiResponses(@ApiResponse(code = 200, message = "成功", response = TaskListVo.class))
    public Result taskList(@RequestBody PageParams params) {
        return taskService.findTaskListByPage(params);
    }

    /**
     * 筛选--任务列表
     *
     * @param params 单独筛选和组合筛选 不需要置顶这个属性  还有搜索栏接口
     */
    @PostMapping("/search")
    @ApiOperation(value = "搜索栏/筛选", notes = "搜索栏/筛选接口")
    @ApiOperationSupport(author = "Tzeao",
            ignoreParameters = {"params.newsType"})
    @ApiResponses(@ApiResponse(code = 200, message = "成功", response = TaskListVo.class))
    public Result search(@RequestBody PageParams params) throws BusinessException {
        return taskService.findTaskListByFilter(params);
    }

    /**
     * 搜索建议
     *
     * @param name 关键词
     * @return 对应的标题
     */
    @GetMapping("/search/{suggestion}")
    @ApiOperation(value = "搜索建议", notes = "搜索建议接口-返回6个建议")
    @ApiOperationSupport(author = "Tzeao")
    @ApiResponses(@ApiResponse(code = 200, message = "成功", response = SuggestionVo.class))
    public Result suggestion(@PathVariable("suggestion") String name) {
        return taskService.findTaskNameBySuggestion(name);
    }
    //    TODO 任务发布时 判断 任务开始时间不能比截止时间晚  开始时间不能比结束时间晚

    /**
     * 根据任务id 查询 任务详情
     *
     * @param id 任务id
     * @return 任务详情
     */
    @GetMapping("/detail/{id}")
    @ApiOperation(value = "任务详情", notes = "任务详情接口")
    @ApiOperationSupport(author = "Tzeao")
    @ApiResponses(@ApiResponse(code = 200, message = "成功", response = TaskDetailVo.class))
    public Result taskDetail(@PathVariable("id") Long id) {
        return taskService.findTaskDetailById(id);
    }

//    TODO 权限拦截 未登录的 无法点击报名-个人中心等（跳转到登录页面）
//    TODO 未认证的 无法点击报名 （跳转到认证页面）

//    TODO 退出登录 注销token 如果无法销毁 你们就放在redis里面
}
